// 登录状态校验
if (localStorage.getItem('user') !== 'true') {
  alert('请先登录系统！');
  location.href = 'login.html';
  throw new Error('未登录，已跳转');
}

// 工具函数
const addQueryParam = (url, param) =>
  url + (url.includes('?') ? '&' : '?') + param;

// 统一 Toast
const showToast = (msg, ok = true) =>
  Toastify({
    text: msg,
    duration: 3000,
    close: true,
    backgroundColor: ok
      ? 'linear-gradient(to right,#00b09b,#96c93d)'
      : 'linear-gradient(to right,#ff5f6d,#ffc371)'
  }).showToast();

// 统一退出
const logout = () =>
  fetch('/api/rest/user/logout', { method: 'POST' })
    .then(() => {
      localStorage.clear();
      location.href = '/login.html';
    });